package com.xiaolun.threadPools;

import java.util.concurrent.*;

public class DiyThreadPoolDemo01 {
	public static void main(String[] args) {
		//打印出12个cpu核数
		System.out.println(Runtime.getRuntime().availableProcessors());
		int number = Runtime.getRuntime().availableProcessors();
		ExecutorService threadPool = new ThreadPoolExecutor(
				2,
//				5,
				number, //替换成集群核数
				2L,
				TimeUnit.SECONDS,
				new ArrayBlockingQueue<Runnable>(3),
				Executors.defaultThreadFactory(),
				//new ThreadPoolExecutor.AbortPolicy()
				//new ThreadPoolExecutor.CallerRunsPolicy()
				//new ThreadPoolExecutor.DiscardOldestPolicy()
				new ThreadPoolExecutor.DiscardOldestPolicy()
		);
		//10个顾客请求
		try {
			for (int i = 1; i <= 10; i++) {
				threadPool.execute(() -> {
					System.out.println(Thread.currentThread().getName() + "\t 办理业务");
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			threadPool.shutdown();
		}
	}
}
